package com.xzx.study;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.SeekBar;

public class ProgressActivity extends AppCompatActivity {

    private LinearLayout mLinearLayout;
    private ProgressBar mProgressBar;
    private SeekBar mSeekBar;

    private SeekBar.OnSeekBarChangeListener mOnSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // 正在移动
            mProgressBar.setProgress(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // 开始移动
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // 停止移动
            mProgressBar.setProgress(seekBar.getProgress());
            if (mProgressBar.getProgress() >= mProgressBar.getMax()) {
                mLinearLayout.setVisibility(View.INVISIBLE);
            } else {
                mLinearLayout.setVisibility(View.VISIBLE);
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress);

        mLinearLayout = findViewById(R.id.lineLayout);
        mProgressBar = findViewById(R.id.progressBar);
        mSeekBar = findViewById(R.id.seekBar);

        mSeekBar.setOnSeekBarChangeListener(mOnSeekBarChangeListener);
    }
}
